from __future__ import absolute_import
import os
import os.path
#import glob
import logging
#from os.path import isdir, join
from forest.registry import register_tool
from forest.tool import Tool

#from forest.tools.system.execute import call

logger = logging.getLogger('forest.tools.system.chmod')

def joinpaths(*args, **kwargs):
    path = os.path.sep.join(args)

    if kwargs.get("follow_symlinks"):
        return os.path.realpath(path)
    else:
        return path

@register_tool('system.move')
def move(src, dst):
    Tool.SIGNAL_TOOL_START(move, level = logging.DEBUG, message = "Move file from %s to %s" % (src, dst))

    if os.path.isdir(dst):
        dst = joinpaths(dst, os.path.basename(src))
    os.rename(src, dst)
    #call(['mv',src, dst])

    Tool.SIGNAL_TOOL_FINISH(move, level = logging.DEBUG, message = "Move file from %s to %s" % (src, dst))
    return dst
